package myiobase;

import java.io.*;

public class IOBase {

    public void writeFile(){
        File file = new File("C:\\Users\\Administrator\\Desktop\\myio\\myio.txt");
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try (OutputStream outputStream = new FileOutputStream(file)) {
            outputStream.write("helloword".getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void readFile(){
        File file = new File("C:\\Users\\Administrator\\Desktop\\myio\\myio.txt");
        try (InputStream inputStream = new FileInputStream(file)) {
            byte[] bytes = new byte[(int) file.length()];
            InputStream inputStream1 = new FileInputStream(file);
            int read = inputStream1.read(bytes);
            System.out.println(new String(bytes));
        }catch (Exception e){
            e.printStackTrace();
        }
    }




    public static void main(String[] args) {
        IOBase ioBase = new IOBase();
        ioBase.writeFile();
        ioBase.readFile();
    }
}
